package de.gwtprime.client.admin;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.RootPanel;

import de.gwtprime.client.PrimeService;
import de.gwtprime.client.PrimeServiceAsync;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Admin implements EntryPoint {

	Button b = new Button("click");
	RichTextArea area;
	
	private final PrimeServiceAsync primeService = GWT.create(PrimeService.class);
	
	public void onModuleLoad() {
			
		
		final Label rpcConnectionLabel = new Label("RPC Status: ");
		RootPanel.get().add(rpcConnectionLabel);
		
		
		
		primeService.testRPCConnection(new AsyncCallback<String>() {
			
			@Override
			public void onSuccess(String result) {
				rpcConnectionLabel.setText(rpcConnectionLabel.getText()+result);
				
			}
			
			@Override
			public void onFailure(Throwable caught) {
				rpcConnectionLabel.setText(rpcConnectionLabel.getText()+"failed"+caught);
				
			}
		});
		
		final Label hibernateStatusLabel = new Label("Hibernate Status: ");
		RootPanel.get().add(hibernateStatusLabel);
		
		
		
		
		
		 area = new RichTextArea();
	    area.ensureDebugId("cwRichText-area");
	    area.setSize("100%", "14em");
	    RichTextToolbar toolbar = new RichTextToolbar(area);
	    toolbar.ensureDebugId("cwRichText-toolbar");
	    toolbar.setWidth("100%");
		RootPanel.get().add(area);
		RootPanel.get().add(toolbar);
	
		
		b.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				
				RootPanel.get().add(new HTML(area.getHTML()));
				
			}
		});
		RootPanel.get().add(b);
	
	}
	
	@UiHandler("b")
	public void onClickEvent(ClickEvent e){
		
	}



}
